<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上市公司指数</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <div class="demoTable">
            <div class="layui-inline searcheBottom">
                证券简称：
                <div class="layui-inline">
                    <input id="securitiesAbbreviation" class="layui-input" name="securitiesAbbreviation" autocomplete="off" placeholder="证券简称"/>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                证券代码：
                <div class="layui-inline">
                    <input id="securitiesCode" class="layui-input" name="securitiesCode" autocomplete="off" placeholder="证券代码"/>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                状态：
                <div class="layui-inline">
                    <select  id="enableFlag" name="enableFlag" class="layui-input" style="padding: 0px 20px;">
                        <option value="">全部</option>
                        <option value="1">使用中</option>
                        <option value="0">已下架</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                <button class="layui-btn" data-type="reload" id="search" >搜索</button>
                <a class="layui-btn layui-btn-primary" href="javascript:;" id="reset">重置</a>
                <a data-opt="add" href="/manage/listed/listedcreate" class="layui-btn" id="addlisted"><i class="layui-icon">&#xe608;</i>添加上市公司指数</a>
            </div>
        </div>
    </blockquote>
    <span style="font-size: 16px;"><b>上市公司指数管理</b></span>
    <table class="layui-hide" id="listedTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;

        //表格渲染
        table.render({
            elem:"#listedTable",
            url:"/manage/listed/aBlockSel",
            method:"post",
            cols:[[
                {field:'id', title: 'ID', sort: true,align:'center',width:100,fixed: 'left'},
                {field:'securitiesCode', title: '证券代码',align:'center',width:150},
                {field:'securitiesAbbreviation', title: '证券简称',align:'center',width:150},
                {field:'projectProgress', title: '项目进展',align:'center', sort: true,width:100},
                {field:'teamBuilding', title: '团队建设',align:'center', sort: true,width:100},
                {field:'outreachCooperation', title: '外联合作',align:'center', sort: true,width:100},
                {field:'capitalInvestment', title: '资本投入',align:'center', sort: true,width:100},
                {field:'implementationSubtotal', title: '实施层面小计',align:'center', sort: true,width:150},
                {field:'companyMarketValue', title: '公司市值',align:'center', sort: true,width:100},
                {field:'windConcept', title: 'wind概念',align:'center', sort: true,width:100},
                {field:'companyItselfSubtotal', title: '公司自身小计',align:'center', sort: true,width:150},
                {field:'strategicLevel', title: '战略层面',align:'center', sort: true,width:100},
                {field:'strategicLevelSubtotal', title: '战略层面小计',align:'center', sort: true,width:150},
                {field:'index', title: '指数',align:'center', sort: true,width:100},
                {field:'enableFlag',width:100, title: '状态', align:'center',
                    templet:function(d){
                        if(d.enableFlag==true){
                            return '<div class="layui-btn layui-bg-green layui-btn-xs">使用中</div>'
                        }else if(d.enableFlag==false){
                            return '<div class="layui-btn layui-bg-gray layui-btn-xs">已下架</div>'
                        }else{
                            return '';
                        }
                    }
                },
                {field: 'tool', title:"操作",align:'left',width:178,align:'center',
                    templet:function(d){
                        var tool = '<a href="#" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                        if(d.enableFlag==true){
                            tool+='<a href="#" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="enable">下架</a>';
                        }else if(d.enableFlag==false){
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable">上架</a>';
                        }
                        tool+='<a href="#" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        return tool;
                    }
                }
            ]],
            limits:[10,15,20,25,30],
            limit:10,
            page:true
        });

        var active = {
            reload: function () {
                var securitiesAbbreviation = $('#securitiesAbbreviation');
                var securitiesCode = $('#securitiesCode');
                var enableFlag = $('#enableFlag option:selected');
                table.reload('listedTable', {
                    where: {
                        securitiesAbbreviation: securitiesAbbreviation.val(),
                        securitiesCode:securitiesCode.val(),
                        enableFlag:enableFlag.val()
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //重置
        $("#reset").on("click",function(){
            securitiesAbbreviation.value = '';
            securitiesCode.value = '';
            enableFlag.value = '';
        });

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "enable") {
            	layer.confirm('确定提交么', function(index){
    		        //向服务端发送删除指令
    		        $.ajax({
                        url:"/manage/listed/aBlockenable",
                        type:"post",
                        dataType:"json",
                        data:{"id":data.id,"enableFlag":data.enableFlag},
                        success:function(resData){
                            layer.alert(resData.msg, {
                                skin: 'layui-layer-molv' //样式类名  自定义样式
                                ,closeBtn: 1    // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: ['确定'] //按钮
                                ,icon: 1    // icon
                                ,yes:function(){
                                    if (resData.code >= 0) {
                                          location.href = "/manage/listed/listedManage";
                                      }
                                }
                            });
                        }
                    })
    		      return false;
                });
               
            } else if (obj.event == "edit") {
                location.href="/manage/listed/listededit?id="+data.id
            } else if (obj.event == "del") {
                layer.confirm('确定删除么？', {icon: 3, title:'提示'},function (index) {
                    $.ajax({
                            url: "/manage/listed/aBlockDel",
                            type: "post",
                            data: { "id": data.id},
                            dataType: "json",
                            success: function (resData) {
                            	layer.alert(resData.msg, {
            	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
            	          		    ,closeBtn: 1    // 是否显示关闭按钮
            	          		    ,anim: 1 //动画类型
            	          		    ,btn: ['确定'] //按钮
            	          		    ,icon: 1    // icon
            	          		    ,yes:function(){
            	          		    	if (resData.code >= 0) {
            	          	                  location.href = "/manage/listed/listedManage";
            	          	              }
            	          		    }});
                            }
                        },
                        function (index, item) {//删除操作后刷新页面
                            location.reload();
                        });
                });
            }
        });
    })
</script>
</body>
</html>